﻿Imports System.Data
Imports System.Data.SqlClient


Public Class Finanzas

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Main.WindowState = FormWindowState.Normal
        Me.Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Main.WindowState = FormWindowState.Normal
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from boleta;"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            DataGridView1.DataSource = tabla

        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from factura;"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            DataGridView1.DataSource = tabla

        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from boleta where numero_bol='" & TextBox1.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            TextBox1.Enabled = False
            TextBox2.Text = tabla.Rows(0)("fecha")
            TextBox3.Text = tabla.Rows(0)("rut_prov")
            TextBox4.Text = tabla.Rows(0)("precio")
            ComboBox1.Text = tabla.Rows(0)("estado_boleta")
            Button5.Enabled = True
            Button4.Enabled = False
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "select * from factura where numero_fact='" & TextBox10.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            TextBox10.Enabled = False
            TextBox9.Text = tabla.Rows(0)("fecha")
            TextBox8.Text = tabla.Rows(0)("rut_const")
            TextBox6.Text = tabla.Rows(0)("precio")
            TextBox11.Text = tabla.Rows(0)("numero_proy")
            ComboBox1.Text = tabla.Rows(0)("estado_fact")
            Button5.Enabled = True
            Button4.Enabled = False
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox1.Enabled = True
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        ComboBox1.Text = ""
        Button5.Enabled = False
        Button4.Enabled = True
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        TextBox10.Enabled = True
        TextBox10.Text = ""
        TextBox9.Text = ""
        TextBox8.Text = ""
        TextBox6.Text = ""
        TextBox11.Text = ""
        ComboBox2.Text = ""
        Button11.Enabled = False
        Button10.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "insert into boleta values ('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox1.Text & "');"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Button6.PerformClick()

            MsgBox("Guardado con exito", MsgBoxStyle.Information, "OK")
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "insert into factura values ('" & TextBox10.Text & "','" & TextBox9.Text & "','" & TextBox8.Text & "','" & TextBox11.Text & "','" & TextBox6.Text & "','" & ComboBox2.Text & "');"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Button9.PerformClick()

            MsgBox("Guardado con exito", MsgBoxStyle.Information, "OK")
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "update boleta set fecha='" & TextBox2.Text & "', rut_prov='" & TextBox3.Text & "', precio='" & TextBox4.Text & "', estado_boleta='" & ComboBox1.Text & "' where numero_bol='" & TextBox1.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Button6.PerformClick()

            MsgBox("Guardado con exito", MsgBoxStyle.Information, "OK")
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        Try
            Dim strCon As String = "Data Source=(local)\SQLEXPRESS ;Initial Catalog=cegan ;Integrated Security=True"
            Dim sql As String = "update boleta set fecha='" & TextBox9.Text & "', rut_const='" & TextBox8.Text & "', precio='" & TextBox6.Text & "', estado_fact='" & ComboBox2.Text & "' where numero_fact='" & TextBox10.Text & "';"
            Dim tabla As New DataTable
            Dim adaptador As New SqlDataAdapter(sql, strCon)
            adaptador.Fill(tabla)

            Button9.PerformClick()

            MsgBox("Guardado con exito", MsgBoxStyle.Information, "OK")
        Catch ex As Exception
            MsgBox("ERROR", MsgBoxStyle.Critical, "Error")

        End Try
    End Sub
End Class